package com.tian.intercptor;

import com.tian.utils.UserCacheUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * {@code @description:} 清理ThreadLocal，防止内存泄漏
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-09-16 10:32
 * {@code @version:} 1.0
 */
@Order(9)
@Slf4j
@Aspect
@Component
public class ThreadLocalCleanupInterceptor {
    @AfterReturning(pointcut = "execution(* com.tian.controller..*.*(..))", returning = "result")
    public void afterReturningAdvice(Object result) {
        // 处理返回值
        UserCacheUtil.clearUser();
    }
}
